package cn.edu.sjtu.literature.db.mapping;

import java.sql.ResultSet;
import java.sql.SQLException;

import cn.edu.sjtu.literature.entity.Category;
import cn.edu.sjtu.literature.entity.Literature;

public class LiteratureResultMappingCallback implements ResultMappingCallback<Literature> {

	@Override
	public Literature doResultMapping(ResultSet rs) throws SQLException {
		Literature literature = new Literature();
		literature.setId(rs.getInt("id"));
		literature.setIssueNo(rs.getString("issue_no"));
		literature.setTitle(rs.getString("title"));
		Category category = new Category();
		category.setId(rs.getInt("categoryId"));
		category.setName(rs.getString("categoryName"));
		literature.setCategory(category);
		literature.setAuthor(rs.getString("author"));
		literature.setAuthorFirm(rs.getString("authorFirm"));
		literature.setAuthorContactInfo(rs.getString("authorContactInfo"));
		literature.setSource(rs.getString("source"));
		literature.setPublishDate(rs.getTimestamp("publish_date"));
		literature.setCreated(rs.getTimestamp("created_date"));
		literature.setCreatedBy(rs.getInt("created_by"));
		literature.setModified(rs.getTimestamp("modified_date"));
		literature.setModifiedBy(rs.getInt("modified_by"));
		return literature;
	}

}
